<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="player.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page errorPage="error.jsp" %>
<%@ include file="header.jspf" %>
<script type="text/javascript" src="script.js"></script>

<%
    Player player = PlayerFabric.getInstance(((Integer) session.getAttribute("sport")).intValue());
    String sport = null;
    Integer sportId = (Integer) session.getAttribute("sport");
    switch (sportId.intValue()) {
        case 1:
            sport = "football";
            break;
        case 2:
            ;
            sport = "basketball";
            break;
        case 3:
            sport = "hockey";
            break;
    }
%>

<br class=clear>

<div class="sportname">
    <h1><%= sport%> -> players
</div>
<br class=clear>
<nav class="submenu">
    <ul>
        <li class="item">
            <a href="teams.jsp">teams</a>
        </li>

        <li class="item">
            <a href="players.jsp">players</a>
        </li>
    </ul>
</nav>

<section class="middle">
<details>
                    <summary>
                        SEARCH
                    </summary>
                <br class=clear>
    <div class="wide-teaser">
        <h3>General info:</h3>
        
        <table class="search-table" cellspacing="0" cellpadding="0">
            <tbody>
                <tr>
                    <th>First Name:
						<input type=text name="firstName" class="search-input"> </th>
                    <th>Last Name:
						<input type=text name="lastName" class="search-input"> </th>
                </tr>
                <tr>
                    <th>Position:
						<input type=text name="position" class="search-input"> </th>                    
                    <th>Country:
						<input type=text name="country" class="search-input"> </th>
                    <th>Year of birth from:
						<input type=text name="dateOfBirthfrom" class="picker"> </th>
                    <th>Year of birth to:
						<input type=text name="dateOfBirthto" class="picker"> </th>
                    
                    
                </tr> 
                <tr>
                    <th>Height from:
						<input type=text name="heightfrom" class="picker"> </th>
                    <th>Height to:
						<input type=text name="heightto" class="picker"> </th>
                    <th>Weight from:
						<input type=text name="weightfrom" class="picker"> </th>
                    <th>Weight to:
						<input type=text name="weightto" class="picker"> </th>
                </tr>
            </tbody>
        </table>
        <br>
        <h3>Stats:</h3>
                                        
        <br>
        <table class="search-table" cellspacing="0" cellpadding="0">
            <tbody>
                <%
                    if (player != null) {
                        List attrs = player.getAttrsNames();
                        List inputs = new ArrayList();
                        for (int i = 0; i < attrs.size(); i++) 
                            if (!attrs.get(i).equals("dateOfBirth") &&!attrs.get(i).equals("height") &&!attrs.get(i).equals("weight") &&!attrs.get(i).equals("teamId") &&!attrs.get(i).equals("country") &&!attrs.get(i).equals("lastName") && !attrs.get(i).equals("firstName") && !attrs.get(i).equals("position") && !attrs.get(i).equals("id") && !attrs.get(i).equals("sportId")) 
                            inputs.add(attrs.get(i));
                        for (int j = 0; j < inputs.size(); j++)    
                            if (j % 3 == 0) {
                %>
                <tr>
                    <th class="criterion"><%=inputs.get(j)%>:</th>
                    <th>
                        &nbsp;from&nbsp;
                        <input type=text name="<%=inputs.get(j)%>from" class=picker>
                        &nbsp; to &nbsp;
                        <input type=text name="<%=inputs.get(j)%>to" class=picker>
                    </th>
                    <%
                    } else if (j % 3 == 1) {%>
                    <th class="criterion"><%=inputs.get(j)%>:</th>
                    <th>
                        &nbsp;from&nbsp;
                        <input type=text name="<%=inputs.get(j)%>from" class=picker>
                        &nbsp; to &nbsp;
                        <input type=text name="<%=inputs.get(j)%>to" class=picker>
                    </th>
                    <%
                    } else if (j % 3 == 2) {%>
                    <th class="criterion"><%=inputs.get(j)%>:</th>
                    <th>
                        &nbsp;from&nbsp;
                        <input type=text name="<%=inputs.get(j)%>from" class=picker>
                        &nbsp; to &nbsp;
                        <input type=text name="<%=inputs.get(j)%>to" class=picker>
                    </th>
                </tr> <%
                }
                
                                                       }
                                              
                
                %>    
					
				

            </tbody>
        </table>
        <br class=clear>
        
				<button class=sportbutton onclick='search()'>search</button>
				&nbsp;&nbsp;
                                <button class=sportbutton style="margin-left:0px !important;" onclick="window.location = 'players.jsp';">clear</button>

    </div>
</details>
    <div class="teaser">
        <br>
        <br>
        <div class="gray_teaser star_teaser">

            <p>Results:</p>

            <br class="clear">

            <div class="teaser-block-left f-left star_teaser">

                <table class="teaser-table" cellspacing="0" cellpadding="0" id="table" name="inputQuery">
                    <thead>
                    <th class="nosort"></th>
                    <th>#</th>
                    <th>name</th>
                    <%
                        if (player != null) {
                            List attrs = player.getAttrsNames();
                            for (int i = 0; i < attrs.size(); i++) {
                                if (!(attrs.get(i).equals("dateOfBirth") ||attrs.get(i).equals("id") ||attrs.get(i).equals("teamId") ||attrs.get(i).equals("firstName") ||attrs.get(i).equals("lastName") ||attrs.get(i).equals("position") || attrs.get(i).equals("name") || attrs.get(i).equals("country"))) {

                    %>
                    <th><%=attrs.get(i)%> </th>
                    <%
                                }
                            }
                        }
                    %>  

                    </thead>
                    <tbody >
                        <jsp:include page="sport?page=players&mode=query" />
                    </tbody>
                </table>
                <script type="text/javascript">
                    var sorter = new TINY.table.sorter("sorter");
                    sorter.head = "head";
                    sorter.asc = "asc";
                    sorter.desc = "desc";
                    sorter.even = "evenrow";
                    sorter.odd = "oddrow";
                    sorter.evensel = "evenselected";
                    sorter.oddsel = "oddselected";
                    sorter.paginate = true;
                    sorter.currentid = "currentpage";
                    sorter.limitid = "pagelimit";
                    sorter.init("table",1);
                </script>
            </div>

        </div>
        <br class="clear">
        
        <button class=sportbutton onclick="remove('players')">remove</button>

    </div>

</section>


<%@ include file="footer.jspf" %>